package com.haiyou.common.spring.log.warning.service;

import java.util.Properties;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

import com.haiyou.common.spring.component.LifecycleableComponent;

import lombok.Getter;

/**
 * 
 * @Description: 警告邮件配置
 * @author xingyuan
 * @date 2023年3月31日 下午4:14:44
 */
@Component
public class LogWarningMailService implements LifecycleableComponent {

	@Getter
	private JavaMailSenderImpl javaMailSender;

	/**
	 * 邮件服务器配置
	 */
	private Properties mailProperties = new Properties();

	public String getSenderMail() {
		return mailProperties.getProperty("spring.mail.username");
	}

	@Override
	public void init() {

		javaMailSender = new JavaMailSenderImpl();

		// SMTP服务器地址
		mailProperties.setProperty("spring.mail.host", com.haiyou.common.system.Properties.log_warning_mail_host());
		// SMTP服务器端口
		mailProperties.setProperty("spring.mail.port",
				String.valueOf(com.haiyou.common.system.Properties.log_warning_mail_port()));
		// 邮件发送者的邮箱地址
		mailProperties.setProperty("spring.mail.username",
				com.haiyou.common.system.Properties.log_warning_mail_username());
		// 邮件发送者的邮箱密码
		mailProperties.setProperty("spring.mail.password",
				com.haiyou.common.system.Properties.log_warning_mail_password());
		// 是否启用SSL
		mailProperties.setProperty("spring.mail.properties.mail.smtp.ssl.enable",
				String.valueOf(com.haiyou.common.system.Properties.log_warning_mail_smtp_ssl_enable()));

		javaMailSender.setHost(mailProperties.getProperty("spring.mail.host"));
		javaMailSender.setPort(Integer.parseInt(mailProperties.getProperty("spring.mail.port")));
		javaMailSender.setUsername(mailProperties.getProperty("spring.mail.username"));
		javaMailSender.setPassword(mailProperties.getProperty("spring.mail.password"));
		javaMailSender.setJavaMailProperties(mailProperties);
	}

	@Override
	public void destory() {

	}

}
